from dataclasses import dataclass
from typing import List, Optional

from config.config import get_pro_config


# 定义模型类
@dataclass
class ProConfModel:
    type: int
    title: str
    login_name: str
    login_password: str
    login_url: str
    server_name: str
    cookie_must_name:str
    cookie_keep_time: int
    # 根据type值获取配置项
    @classmethod
    def get_by_type(cls, config_type: int) -> Optional['ProConfModel']:
        """
        根据type值获取配置项
        :param config_type: 要查找的type值
        :return: 找到的ProModel实例或None
        """
        configs = get_pro_config()
        # 将字典转换为ProModel实例
        matched = next((cls(**config) for config in configs if config['type'] == config_type), None)
        return matched
        # 测试数据


